

import BaseHelper from "./BaseHelper";
import ChannelEvent from "./ChannelEvent";
import ChannelUtils from "./ChannelUtils";
import SDKEvent from "../sdk/tools/SDKEvent";
export default class VivoHelper extends BaseHelper {
    protected zsConfig = {
        zs_version: '1.0',
        zs_switch: 0,//误触总开关(1-开 0-关)
        zs_banner_city: 0,
        zs_banner_system: '',
        zs_native_click_switch: 0,
        zs_native_slide_switch: 0,
        zs_banner_native_switch: 0,
        zs_native_close_num: 0,
        zs_banner_native_time: 0,
        zs_native_touch_switch: 0,//为1时，关闭按钮尺寸为40*40，实际可点击范围为32*32；为0时点击范围为40*40
        zs_native_next_limit: 0,//插屏原生广告页面，原生卡片和“点击查看”按钮中间新增一个“下一步”按钮（如上图），按钮是否展示接入开关zs_native_next_limit
        zs_native_limit: 0,//游戏进行页面每隔30s弹出一次插屏式原生广告
        zs_native_gap_time: 0//游戏过程中间隔X秒弹出激励视频弹窗，同时展 示嵌入式原生，
    }

    constructor() {
        super();
        this.setVersion('1.2')
        this.login()
        this.loadConfig()
        SDKEvent.instance().on(SDKEvent.REWARD_AD_CLOSE, this.rewardClose, this)
        SDKEvent.instance().on(SDKEvent.REWARD_AD_OPEN, this.rewardOpen, this)
    }

    rewardOpen() {
       
    }

    rewardClose() {
       
    }

    getNativeBannerRefreshTime() {
        if (this.zsConfig.zs_banner_native_time) {
            return this.zsConfig.zs_banner_native_time
        }
        return 30;
    }
    getBannerWitch() {
        if (this.zsConfig.zs_banner_native_switch) {
            return this.zsConfig.zs_banner_native_switch
        }
        return 0;
    }
    getNativeCloseNum() {
        if (this.zsConfig.zs_native_close_num) {
            return this.zsConfig.zs_native_close_num
        }
        return 0;
    }
    hasNativeNextLimit() {
        return this.isVersion() && this.zsConfig.zs_native_next_limit == 1;
    }
    getNativeSlide() {
        if (this.zsConfig.zs_native_slide_switch) {
            return this.zsConfig.zs_native_slide_switch
        }
        return 0;
    }
    hasNativeTouchSwitch() {
        return this.isVersion() && this.zsConfig.zs_native_touch_switch == 1
    }

    getzs_native_gap_time() {
        if (this.zsConfig.zs_native_gap_time) {
            return this.zsConfig.zs_native_gap_time
        }
        return 0;
    }

    hasNativeAd() {
        return true;
    }

    hasNativeLimit() {
        return this.isVersion() && this.zsConfig.zs_native_limit == 1
    }

    loadConfig() {
        let zsSdk = window['zs'].sdk
        zsSdk.loadCfg((result) => {
            this.zsConfig = result;
            console.log(' result === ', result)
            //test
            // this.zsConfig.zs_native_limit = 1;
            // this.zsConfig.zs_banner_native_switch = 0;
            // this.zsConfig.zs_native_close_num = 1;
            // this.zsConfig.zs_native_touch_switch = 1;

            ChannelEvent.instance().emit(ChannelEvent.LOAD_CONFIG)
        }, (err) => {
            console.log(' err === ', err)
            setTimeout(() => {
                this.loadConfig()
            }, 3000);
        });
    }

    login(isInit: boolean = true) {
        let zsSdk = window['zs'].sdk
        zsSdk.login((openid) => {
            console.log(' msg ', openid)
        }, (err) => {
            console.log('login error ', err)
            setTimeout(() => {
                this.login(isInit)
            }, 3000);
        })
    }
    isOpenNativeErrorClick() {
        return this.isVersion() && this.zsConfig.zs_native_click_switch == 1
    }
    isVersion() {
        return ChannelUtils.compareVersion(this.verson, this.zsConfig.zs_version) == 1
    }
    isErrorClickOpen() {
        return this.isSwtichOpen() && this.isSystemOpen() && this.zsConfig.zs_banner_city == 1
    }
    isSwtichOpen() {
        return this.zsConfig.zs_switch == 1
    }

    isSystemOpen() {
        if (this.zsConfig.zs_banner_system == "") {
            return true;
        }
        return this.getOS() != this.zsConfig.zs_banner_system
    }
    getBannerRefreshTime() {
        return 30
    }
    hasLoginBanner() {
        return true;
    }
    getProcessTime() {
        return 0
    }

    firstExport() {
        return false;
    }

    hasEgg() {
        return false;
    }

    hasDiamonView() {
        return false;
    }
}